import { BaseCommand, CSLineSegments } from '@amcax/base';
import { wsApi } from '../../../../server/wsApi';
import { ctx2 } from '../../../../module';

export const clearAllModels = async () => {
  const length = ctx2.cadScene.edgeGroup.children.length;
  if (length > 0) {
    const model_dxids = [];
    for (let i = 0; i < length; i++) {
      const edge = ctx2.cadScene.edgeGroup.children[i] as CSLineSegments;
      const dxid = edge.modelDxid;
      if (dxid) {
        model_dxids.push(dxid);
      }
    }
    await wsApi.delete(model_dxids);
    ctx2.viewer.requestRender();
  }
};

export const cmdClear: BaseCommand = {
  id: 'cmdClear',
  icon: 'commands/airfoil/delete',
  label: 'clearScene',
  noHighlight: true,

  invoke: clearAllModels,
};
